<extend name="Public/base"/>

<block name="style">
    <style type="text/css">
.btn{

    background: #09c;
}
.btn:hover{
    background: #09c;
}
        .zaixian_shou{
            width: 33px;
            height: 33px;
            border-radius: 50% 50%;

        }
        .path2_status{
            width: 33px;
            height: 33px;
            border-radius: 50% 50%;

        }
        .frozen{
            width: 33px;
            height: 33px;
            border-radius: 50% 50%;

        }
        ._tixian{
            width: 33px;
            height: 33px;
            border-radius: 50% 50%;

        }
      .side-sub-menu > li > .item {
                color: #000;
                font-family: '宋体';
                font-size:15px;padding:0px;
                line-height: 25px;
            }
    .sidebar {
        background: #3697A0;
        position: absolute;
    }   

     /* 头部Logo,主导航*/
            body{
                color:#000;
                font-family: '宋体';
                font-weight: 900;
            }
            .header {
                background-color:   #3697A0;
                height: 45px;
            }
            /* 主导航 */
            .main-nav a {
                height: 45px;
                color: #150303;
            }
            .main-nav a:hover {
                height: 45px;
                background-color:#70bcf3;
                color: #150303;
            }
            .main-nav .current{
                height: 45px;
                background-color: #70bcf3;
            }
            .main-nav .current a {
                height: 45px;
                background-color: #70bcf3;
                color: #150303;
            }
            .logo{
                height: 45px;
                background: #ccc;
            }
            .sidebar{
                margin-top:-5px;
                background:     #3697A0;
                color: #000;
                position: fixed;
                height: 110%;
                margin-top:-40px;
            }
            .subnav h3{
                color: #000;
            }

            .main-nav {
                /*width:100%;*/
                float: none;
                height: auto;
            }

            .mainnav {
                /*height: auto;*/
                height: 100%;
            }

            .main-nav li{
                float: none;
                width:180px;
            }

                        /* Table Head */
.data-table thead th {
background-color: rgb(81, 130, 187);
color: #fff;
border-bottom-width: 0;
}

/* Column Style */
.data-table td {
color: #000;
}
/* Heading and Column Style */
.data-table tr, .data-table th {
border-width: 1px;
border-style: solid;
border-color: rgb(81, 130, 187);
}

/* Padding and font style */
.data-table td, .data-table th {
padding: 5px 10px;
font-size: 12px;
font-family: Verdana;
font-weight: bold;
}
    </style>
</block>

<block name="body">

<!-- 	<div class="main-title" style="margin-top:5px;">
		<h2>商户列表</h2>
	</div> -->
        <div class="cf" style="margin-top: 5px;margin-left:-50px;margin-bottom:10px;">
            <div style="float: left;padding-left: 50px;" class="">总人数：<span style="color: #ff6600">{$usercount}</span>人</div>
            <div style="float: left;padding-left: 50px;" class="">未提现总佣金：<span style="color: #ff6600">{$sum.yongjin}</span>元</div>

            <div style="float: left;padding-left: 50px;" class="">未提现总分润:<span style="color: #c43c35">{$sum.divide}</span>元</div>
            <div style="float: left;padding-left: 50px;" class="">今日总交易量:<span style="color: #c43c35">{$sum.t_money}</span>元</div>
            <div style="float: left;padding-left: 50px;" class="">今日进账：<span style="color: #0000ff">{$sum.td_in}</span>元</div>
            <div style="float: left;padding-left: 50px;" class="">今日提现:<span style="color: #c43c35">{$sum.td_out}</span>元</div>

        </div>
                <div class="cf">


                    <!--<div class="search-form fr cf">-->
                        <!--<div class="sleft">-->
                            <!--<div class="drop-down drop-down_type" style="width: 150px;">-->
                                <!--<span id="sch-sort-txt_type"  style="width: 115px;" class="sort-txt" data="">通道选择</span>-->
                                <!--<i class="arrow arrow-down"></i>-->
                                <!--<ul id="sub-sch-menu_type" class="nav-list hidden">-->
                                    <!--<li><a href="javascript:;" style="width: 115px;" value="1">信用卡</a></li>-->
                                    <!--<li><a href="javascript:;" style="width: 115px;" value="2">花呗</a></li>-->
                                    <!--<li><a href="javascript:;" style="width: 115px;" value="3">花呗分期</a></li>-->
                                    <!--<li><a href="javascript:;" style="width: 115px;" value="4">条码</a></li>-->
                                <!--</ul>-->
                            <!--</div>-->

                        <!--</div>-->

                        <!--<button class="btn kg" >开启</button>-->
                        <!--<button class="btn kg" >关闭</button>-->

                    <!--</div>-->


                    <!-- 高级搜索 -->
                    <div class="search-form fr cf">
                        <div class="sleft">
                            <input name="title" class="search-input" style="width:200px;" value="" placeholder="请输入名字、店名、商户编号" type="text">
                            <a class="sch-btn" href="javascript:;" id="search" url="{:U('find_one')}"><i class="btn-search"></i></a>
                        </div>

                    </div>

                    <button class="btn yh_delete" >删除用户</button>
                    <a class="btn" href="{:U('add_user')}" target="_blank">添加用户</a>
                    <button class="btn all_tixian">一键提现</button>
                </div>

	<div class="data-table table-striped" >
		<table style="font-size:14px;">
			<thead>
				<tr><th class="row-selected row-selected"><input class="check-all" type="checkbox"/></th>
                    <th>用户UID</th>
					<th>用户编号</th>
                    <th>姓名</th>
                    <th>手机号码</th>
                    <th>店铺名称</th>
                    <th>支付宝账号</th>
                    <!--<th>账户余额</th>-->
                    <th>交易量</th>
                    <th>在线收款状态</th>
                    <th>提现状态</th>
                    <th>上级/所属层级</th>
                    <th>未提现金额</th>
                    <th>提现</th>
                    <th>码商</th>
					<th>操作</th>
				</tr>
			</thead>
			<tbody>
				<notempty name="_list">
				<volist name="_list" id="rows">
					<tr>
                        <td><input class="ids" type="checkbox" name="id[]" value="{$rows['uid']}" /></td>
                        <td class="uid">{$rows['uid']}</td>
						<td>{$rows['yh_uid']}</td>
						
                        <td>{$rows['name']}</td>
                        <td>{$rows['phone']}</td>
                        <td>{$rows['shop_name']}</td>
                        <td>{$rows['alipay']}</td>
                        <php>
                            $one=D('Gather')->where('uid='.$rows['uid'])->find();
                        </php>
                        <!--<td>{$one['money']}</td>-->
                        <php>
                            $money1=D('Dingdan')->where('uid='.$rows['uid'])->sum('yh_money');
                            $money2=D('Xyk')->where('uid='.$rows['uid'])->sum('yh_money');
                            $money3=D('Wxpay')->where('uid='.$rows['uid'])->sum('yh_money');
                            $money4=D('Divided')->where('uid='.$rows['uid'])->sum('yh_money');
                            $money5=D('Youka')->where('uid='.$rows['uid'])->sum('yh_money');
                            $money6=D('Split')->where('uid='.$rows['uid'])->sum('yh_money');

                            $_total=$money1+$money2+$money3+$money4+$money5+$money6;
                        </php>
                        <td>{$_total}</td>


                
                        <td>
                            
                            <if condition="$one[status] eq 0">

                                <button class="zaixian_shou">关闭</button>
                                <else/>
                                <button class="zaixian_shou">开启</button>

                            </if> 

                        </td>


                        <td class="_frozen">
                            
                            <if condition="$one[frozen] eq 1">

                                <button class="frozen">正常</button>
                                <else/>
                                <button class="frozen">冻结</button>

                            </if> 

                        </td>

                        
                        <td>

                            <php>
                                if($rows['pid']>1){
                                        $pa=D('Ptyh')->where('uid='.$rows['pid'])->find();
                                        $uid=$pa['uid'];

                                        $name=$pa['name'];
                                        if(empty($name)){
                                            $uid=0;
                                            $name="该上级未认证";
                                        }
                                    }else if($rows['pid']==0||$rows['pid']==1){
                                        $uid=0;
                                        $name="直属平台"; 
                                    }
                            </php>
                            <if condition="$uid eq 0">
                                        {$name}
                                <else/>
                                <a href="{:U('yh_view?uid='.$uid)}">
                                    {$name}/{$rows.level}
                                </a>
                            </if>
                            
                        </td>
                        <td>{$rows['gather']['yongjin']+$rows['gather']['fenrun']}</td>
                        <td class="">
                                <button class="_tixian">提现</button>

                        </td>

                        <td class="">
                            <php>
                                $isMashang = M('kbxx')->where('uid='.$rows['uid'])->count();

                            </php>
                            <if condition="$isMashang eq 1">
                                <button class="unsetkbxx" data-id="{$rows.uid}">取消码商</button>

                            <else/>
                                <button class="setkbxx" data-id="{$rows.uid}">设置为码商</button>

                            </if>


                        </td>

                                                  
						<td>
							<a title="详细" href="{:U('yh_view?uid='.$rows['uid'])}">详细</a>
                            
						</td>
					</tr>
				</volist>
				<else/>
				<td colspan="14" class="text-center"> aOh! 暂时还没有内容! </td>
				</notempty>
			</tbody>
		</table>

	</div>

    <div class="page"  style="float:left;margin-right:300px;margin-top:32px;">{$_page}</div>
</block>

<block name="script">
    <link href="/Public/static/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
    <link href="/Public/static/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
    <script type="text/javascript" src="/Public/static/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript" src="/Public/static/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script type="text/javascript">
    $(function(){

        //搜索功能
        $("#search").click(function(){
            var url = $(this).attr('url');
            var status = $("#sch-sort-txt").attr("data");
            var type   = $("#sch-sort-txt_type").attr("data");
            var query  = $('.search-form').find('input').serialize();
            query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g,'');
            query = query.replace(/^&/g,'');
            if(status != ''){
                query += '&status=' + status + "&" + query;
            }
            if(type != ''){
                query += '&type=' + type + "&" + query;
            }
            if( url.indexOf('?')>0 ){
                url += '&' + query;
            }else{
                url += '?' + query;
            }
            window.location.href = url;
        });

            //回车搜索
    $(".search-input").keyup(function(e){
        if(e.keyCode === 13){
            $("#search").click();
            return false;
        }
    });


        Think.setValue("extend", {$info.extend|default=0});
        //导航高亮
        highlight_subnav('{:U('ptyh')}');




        /* 状态搜索子菜单 */
        $(".search-form").find(".drop-down1").hover(function(){
            $("#sub-sch-menu").removeClass("hidden");
        },function(){
            $("#sub-sch-menu").addClass("hidden");
        });
        $("#sub-sch-menu li").find("a").each(function(){
            $(this).click(function(){
                var text = $(this).text();
                $("#sch-sort-txt").text(text).attr("data",$(this).attr("value"));
                $("#sub-sch-menu").addClass("hidden");
            })
        });

        $(".search-form").find(".drop-down_type").hover(function(){
            $("#sub-sch-menu_type").removeClass("hidden");
        },function(){
            $("#sub-sch-menu_type").addClass("hidden");
        });

        $("#sub-sch-menu_type li").find("a").each(function(){
            $(this).click(function(){
                var text = $(this).text();
                $("#sch-sort-txt_type").text(text).attr("data",$(this).attr("value"));
                $("#sub-sch-menu_type").addClass("hidden");
            })
        });
        $('#time-start').datetimepicker({
            format: 'yyyy-mm-dd',
            language:"zh-CN",
            minView:2,
            autoclose:true
        });

        $('#time-end').datetimepicker({
            format: 'yyyy-mm-dd',
            language:"zh-CN",
            minView:2,
            autoclose:true
        });





        $('.zaixian_shou').click(function(){
            var current=$(this)
            var text=current.html();
            var _this=current.parent().parent().find('.uid');
            var uid =_this.text();
            if(text=='开启'){
              var  status=0;
            }else{
              var  status=1;
            }
            $.ajax({
                type:'post',
                data:{'status':status,'uid':uid,'type':'status'},
                url:"{:U('ptyh')}",
                success:function(m){
                    if(m==1){
                        // current.html('')
                        if(status==1){

                            current.html('开启')
                        }else{
                            current.html('关闭')
                        }
                        
                    }
                }

            })
        })



        // $('.path2_status').click(function(){
        //     var current=$(this)
        //     var text=current.text();
        //     var _this=current.parent().parent().find('.uid');
        //     var uid =_this.text();
        //     if(text=='开启'){
        //       var  status=0;
        //     }else{
        //       var  status=1;
        //     }
        //     $.ajax({
        //         type:'post',
        //         data:{'path2_status':status,'uid':uid,'type':'path2_status'},
        //         url:"{:U('ptyh')}",
        //         success:function(m){
        //             if(m==1){
        //                 current.text('')
        //                 if(status==1){
        //                     current.text('开启')
        //                 }else{
        //                     current.text('关闭')
        //                 }
                        
        //             }
        //         }

        //     })
        // })



        $('._tixian').click(function(){
            var current=$(this)
            var _this=current.parent().parent().find('.uid');
            var uid =_this.text();
            $.ajax({
                type:'post',
                data:{'uid':uid},
                url:"{:U('tixian_by')}",
                success:function(m){
                    alert(m)
                }

            })
        })

    })


</script>
<script type="text/javascript">
        $('._frozen').on('click','.frozen',function(){
        // $('.frozen').click(function(){
            var current=$(this)
            var text=current.html();

            var _this=current.parent().parent().find('.uid');
            var uid =_this.text();
            
            if(text=='正常'){
                var  status=0;
                var str=''
                str+='<input class="input" type="text" style="width:100%;height:30px;line-height:30px;" name="content" value="" placeholder="填写冻结原因">';
                current.parent().html(str);


               $('._frozen').on('blur','input',function(){
                    var frozen_val=$('._frozen input').val();
                    
                    $.ajax({
                        type:'post',
                        data:{'frozen':status,'uid':uid,'type':'frozen','frozen_val':frozen_val},
                        url:"{:U('ptyh')}",
                        success:function(m){
                          
                            if(m==1){
                                if(status==1){
                                    var btn='<button class="frozen">正常</button>';

                                    $('._frozen input').parent().html(btn);
                                }else{
                                    alert('冻结成功！')
                                    var btn='<button class="frozen">冻结</button>';
                                    // alert(btn)

                                    $('._frozen input').parent().html(btn);

                                }
                                
                            }
                        }

                    })

              });
              





            }else{
              var  status=1;
              $.ajax({
                type:'post',
                data:{'frozen':status,'uid':uid,'type':'frozen'},
                url:"{:U('ptyh')}",
                success:function(m){
                    if(m==1){
                        // current.html('')
                        if(status==1){

                            current.html('正常')
                        }else{
                            current.html('冻结')
                        }
                        
                    }
                }

            })
            }
            
        })

    $('.kg').click(function(){
        var obj = document.getElementsByClassName("ids");
        check_val = [];
        for(k in obj){
            if(obj[k].checked)
                check_val.push(obj[k].value);
        }
        var type=$('#sch-sort-txt_type').attr('data');
        var _this=$(this).text()
        if(_this=='开启'){
            var status=1;
        }else{
            var status=0;
        }
            $.ajax({
                type:'post',
                data:{'ids':check_val,'type':type,'status':status},
                url:"{:U('ptyh')}",
                success:function(m){
                    alert(m)
                        // alert("提交扣款人数："+ids+"，成功："+success+"，失败："+default+"。失败合同号："+ht+"对应失败原因："+error)
                }
            })
    })

    //添加用户
    $('.yh_add').click(function(){
        location.href = '{:U("add_user")}';
    });

    $('.yh_delete').click(function(){
        var obj = document.getElementsByClassName("ids");
        var check_val = [];
        for(k in obj){
            if(obj[k].checked)
                check_val.push(obj[k].value);
        }

        $.ajax({
            type:'post',
            data:{'uids':check_val},
            url:"{:U('yh_delete')}",
            success:function(m){
                // alert(m)
                if(m==0){
                    alert('请选择需要删除的用户！')
                }else if(m==1){
                    alert('删除成功！')
                    location.reload()
                }
            }
        })

        
    })

    /**
     * 设置用户为码商
     */
    $('.setkbxx').click(function(){
        var uid = $(this).data('id');
        var url = "{:U('Alipay/ptyh')}";

        $.post(url,{type:'setkbxx',uid:uid},function (ret) {
            // todo

            location.reload();
            
        },'json');

    });

    //取消用户码商
        $('.unsetkbxx').click(function(){
            var uid = $(this).data('id');
            var url = "{:U('Alipay/ptyh')}";

            $.post(url,{type:'unsetkbxx',uid:uid},function (ret) {
                // todo
                console.log(ret);
                location.reload();

            },'json');

        });

        //一建提现
        $('.all_tixian').click(function(){
            var url = "{:U('Alipay/alltixian')}";
            $.get(url,function (ret) {
                console.log(ret);
                layer.msg('一键提现成功');
            });
        });




</script>
</block>